import requests
from Finance_api import app


class InvestmentProcessAPI:
    def __init__(self):
        # 获取图片验证码接口
        self.url_verify_code = app.BASE_URL + "common/public/verifycode1/" + app.nums
        # 获取手机验证码接口
        self.url_phone_code = app.BASE_URL + "member/public/sendSms"
        # 获取注册接口
        self.url_register = app.BASE_URL + "member/public/reg"
        # 获取登录接口
        self.url_login = app.BASE_URL + "/member/public/login"
        # 获取开户接口
        self.url_oaa = app.BASE_URL + "/trust/trust/register"
        # 获取第三方开户接口
        self.url_ooaa = app.OAA_URL
        # 获取充值图片验证码(整数)接口
        self.url_recharge_code = app.BASE_URL + "/common/public/verifycode/" + app.nums
        # 获取后台充值接口
        self.url_background_recharge = app.BASE_URL + "/trust/trust/recharge"
        # 获取第三方充值接口
        self.url_other_recharge = app.OAA_URL
        # 获取后台投资接口
        self.url_background_investment = app.BASE_URL + "/trust/trust/tender"
        # 获取第三方投资接口
        self.url_other_investment = app.OAA_URL

    # 获取图片验证码
    def get_verify_code(self, session):
        return session.get(self.url_verify_code)

    # 获取手机验证码
    def get_phone_code(self, session, phone, verifycode, type):
        get_data = {
            "phone": phone,
            "imgVerifyCode": verifycode,
            "type": type
        }
        return session.post(url=self.url_phone_code,
                            data=get_data,
                            headers=app.headers_data)

    # 注册
    def register(self, session, register_data):
        return session.post(url=self.url_register,
                            data=register_data,
                            headers=app.headers_data)

    # 登录
    def login(self, phone, password):
        login_data = {
            "keywords": phone,
            "password": password
        }
        return requests.post(url=self.url_login,
                             data=login_data)

    # 开户
    def oaa(self):
        return requests.post(url=self.url_oaa,
                             headers=app.headers_data)

    # 第三方开户
    def ooaa(self):
        return requests.post(url=self.url_ooaa,
                             headers=app.headers_data,
                             data=app.account_data)

    # 获取充值图片验证码
    def get_recharge_code(self):
        return requests.get(self.url_recharge_code)

    # 后台充值
    def background_recharge(self, br_recharge_data):
        return requests.post(url=self.url_background_recharge,
                             headers=app.headers_data,
                             data=br_recharge_data)

    # 第三方充值
    def other_recharge(self):
        return requests.post(url=self.url_other_recharge,
                             headers=app.headers_data,
                             data=app.account_data)

    # 后台投资
    def background_investment(self, br_investment_data):
        return requests.post(url=self.url_background_investment,
                             headers=app.headers_data,
                             data=br_investment_data)

    # 第三方投资
    def other_investment(self):
        return requests.post(url=self.url_other_investment,
                             headers=app.headers_data,
                             data=app.account_data)
